package com.onejson.ojmall.controller;


import com.onejson.ojmall.common.domain.PageResult;
import com.onejson.ojmall.common.apiencrypt.domain.ValidateList;
import com.onejson.ojmall.common.domain.ResponseDTO;
import com.onejson.ojmall.model.form.UserBatchForm;
import com.onejson.ojmall.model.form.UserForm;
import com.onejson.ojmall.model.form.UserQueryForm;
import com.onejson.ojmall.model.vo.UserVO;
import com.onejson.ojmall.service.impl.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 用户表控制器
 *
 * @author wxx
 */
@Slf4j
@RestController
@Tag(name = "用户表")
public class UserController {


    //【用户表】Service层

    @Resource
    private UserService userService;


    @Operation(summary = "【用户表】 - 查询")
    @PostMapping("/zichan/user/queryPage")
    public ResponseDTO<PageResult<UserVO>> queryUser(@RequestBody @Valid UserQueryForm queryForm) {
        return ResponseDTO.ok(userService.getList(queryForm));
    }

    @Operation(summary = " 【用户表】 - 详情")
    @GetMapping("/zichan/user//{detailId}")
    public ResponseDTO<UserVO> getInfo(@PathVariable("detailId") String detailId) {
        return ResponseDTO.ok(userService.queryById(detailId));
    }

    @Operation(summary = " 【用户表】 - 添加")
    @PostMapping("/zichan/user/add")
    public ResponseDTO<String> addUser(@RequestBody @Valid UserForm addForm) {
        return userService.addUser(addForm);
    }

    @Operation(summary = "【用户表】 - 更新")
    @PostMapping("/zichan/user/update")
    public ResponseDTO<String> updateUser(@RequestBody @Valid UserForm updateForm) {
        return userService.updateUser(updateForm);
    }

    @Operation(summary = "【用户表】 - 批量更新")
    @PostMapping("/zichan/user/batchUpdate")
    public ResponseDTO<String> batchUpdateUser(@RequestBody @Valid UserBatchForm userBatchForm) {
        return userService.batchUpdateUser(userBatchForm);
    }

    @Operation(summary = "【用户表】 - 批量删除")
    @PostMapping("/zichan/user/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<String> idList) {
        return userService.batchDelete(idList);
    }

    @Operation(summary = "【用户表】 - 单个删除")
    @GetMapping("/zichan/User/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable String id) {
        return userService.delete(id);
    }

}

